package com.api.devices.domain.query;


import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.api.common.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Getter
@Setter
class ElementTreeQuery{
    private Long elementId;
    private JSONObject elementNameLocales;
    @JsonIgnore
    private String strElementName;
    private String elementCode;
    private String type = "element";
    private Set<String> datColSet;
    private Integer ipcSlot;

    public void setStrElementName(String strElementName) {
        if(StringUtils.isNoneBlank(strElementName)){
            this.elementNameLocales = JSONObject.parseObject(strElementName);
        }
        this.strElementName = strElementName;
    }

    public void setDatColSet(String strDatColSet) {
        if (StringUtils.isNotBlank(strDatColSet)) {
            List<String> ja = JSONArray.parseArray(strDatColSet).toList(String.class);
            this.datColSet = new HashSet<>(ja);
        } else {
            this.datColSet = null;
        }
    }
}